{ Test1.m
  include Test
}

Program Strip;


Var i,Fsiz : Integer;
    s      : String;
    so,de  : File of Integer;

Procedure Unit;
Var Wert,anz : Integer;
Begin
 Read(so,anz);
 Write(de,anz);
 While anz>0 Do
  Begin
   Anz:=Anz-1;
   Read(so,Wert);
   Write(de,Wert)
  End
End;

Procedure Symbol;
Var Wert,anz,Last : Integer;
    Ref           : Boolean;
Begin
 Read(So,Last);
 While Last<>0 Do
  Begin
   Anz:=Last;
   If Anz<0
      then Ref:=True
      else Ref:=False;
   Write(De,Anz);
   Anz:=Anz and $ffff;
   While Anz>0 DO
    Begin
     Read(so,Wert);
     Write(De,Wert);
     Anz:=Anz-1
    End;
   If Ref
      then Begin
            Read(So,Anz);
            Write(De,Anz);
            While Anz>0 DO
             Begin
               Read(So,Wert);
               Write(De,Wert);
               ANz:=Anz-1
             End
           End
      else Begin
            Read(so,Wert);
            Write(de,Wert)
           End;
   Read(so,Last)
  End;
 Write(De,Last)
End;

Procedure Reloc;
Var Wert,Anz : Integer;
Begin
 Read(so,Anz);
 Writeln('Reloc=',Anz);
 If Anz>0
    then Begin
          Write(De,$3ec);
          While Anz>0 Do
           Begin
            Write(De,Anz);
            Read(so,Wert); { Hunk-Nummer }
            Write(de,Wert);
            While Anz>0 DO
             Begin
              Read(So,Wert);
              Write(De,Wert);
              Anz:=Anz-1
             End;
            Read(so,Anz)
           End;
           Write(De,0)
         End
End;

Procedure Process( wert : Integer);
Begin
 Case wert Of
  $3e7,
  $3e8,
  $3e9,
  $3ea,
  $3eb : Begin
           Write(De,Wert);
           Unit
         End;
  $3f2 : Write(De,$3f2);
  $3ef,
  $3f0 : Begin
          Write(De,Wert);
          Symbol
         End;
  $3ec : Reloc;
 End
End;

Begin
 Writeln('Strip 0.2');
 Writeln('Entfernt leere Hunk_Relocs, da ALINK sonst abstürzt');
 s:=ParamStr;
 If s=''
    then Begin
           s:='ScLib'
         End
    else s:=Copy(S,1,Length(s)-1);
 Reset(so,s);
 Fsiz:=FileSize(so);
 Rewrite(de,'ScLibNeu');
 While Not(EOF(So)) Do
  Begin
   Read(so,i);
   Process(i)
  End;
 Close(De);
 Close(so)
End.
